<template>
    <div class="row">
        <div class="col-3" v-for="(item,index) in dataUrls">
            <web_fill_input :id="index" :get-name="item.getName" :form-name="item.formName" v-bind:data-u-r-l="item.url" :key_value="req" :place-holder="item.placeHolder" @valueChanged="doData"/>
        </div>
        <div class="col-2">
            <el-input type="text" v-model="keyWord" @keyup.enter="doSearch" placeholder="输入搜索关键字"/>
        </div>
        <div class="col-1" style="">
            <el-button id="search_btn" type="warning" @click="doSearch">搜索</el-button>
        </div>
    </div>
</template>

<script>
    import Web_fill_input from "./Web_fill_input";
    import axios from "axios";
    let searchMap = new Map()
    export default {
        name: "Web_search_box",
        components: {
            Web_fill_input
        },
        props: ['dataUrls','searchReqUrl'],
        data(){
            return{
                keyWord:'',
                req:''
            }
        },
        //传入：
        methods:{
            doSearch(){
                searchMap.set('keyword',this.keyWord)
                //if(searchMap.size<this.dataUrls.length + 1) {alert('请设置全部限定条件');return;}
                //alert("向" + this.searchReqUrl + "发起搜索");

                let searchReq = this.searchReqUrl;
                let first = true
                searchMap.forEach((value,key)=>{
                    if(first){
                        searchReq += '?';
                        first = false;
                    }else {
                        searchReq += '&';
                    }
                    searchReq += (key + '=' + value)
                })
                if(first) searchReq+='?';
                //alert("请求格式：" + searchReq)
                //标准的get请求 http://www.searchUrl.com?option1=value1&option2=value2
                axios.get(searchReq).then(e => {
                    this.$emit('SearchResult',searchReq)
                })
            },
            doData(selectionName,selectionID,formName){
                searchMap.set(formName,selectionID)
                this.calcReq();
            },
            calcReq(){
                let searchReq = '';
                let first = true;
                searchMap.forEach((value,key)=>{
                    searchReq += '&';
                    searchReq += (key + '=' + value)
                })
                console.log('将Req改为',searchReq);
                this.req = searchReq;
            }
        }
    }
</script>

<style scoped>

</style>